package AlgorithmStudy.study;


import AlgorithmStudy.study.study01.SortAlgorithm;
import AlgorithmStudy.study.study01.Test01;
import bean.User;

import java.applet.AppletContext;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.ReentrantLock;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public final class Main {

    public static void main(String[] args) throws IOException {

        List<User> list = new ArrayList();
        User user1 = new User();
        User user2 = new User();
        User user3 = new User();
        user1.setCode("code1");
        user1.setName("name1");
        user1.setUrl("url1");
        user2.setCode("code1");
        user2.setName("name2");
        user2.setUrl("url2");
        user3.setCode("code3");
        user3.setName("name3");
        user3.setUrl("url3");
        list.add(user1);
        list.add(user2);
        list.add(user3);

        Map<String, List<User>> map = list.stream().collect(Collectors.groupingBy(User::getCode));
        map.forEach((a,b) -> System.out.println(a + "--" + b) );

        // 构造方法
//        Test01 test01 = new Test01("eeee");

        // 排序
//        int[] arr = {5,8,3,1,4,7};
//        SortAlgorithm sortAlgorithm = new SortAlgorithm();

        // JDK中数组的排序使用的快排；Collections.sort使用的是归并排序【或TimSort: 归并+插入排序】
//        Arrays.sort(arr);
//        Collections.sort(null);
//        System.out.println("Java Array sort：" + Arrays.toString(arr));

        // 冒泡排序
//        sortAlgorithm.bubbleSort(arr);

        // 简单选择排序
//        sortAlgorithm.selectSort(arr);

        // 直接插入排序
//        sortAlgorithm.insertSort(arr);

        // 希尔排序
//        sortAlgorithm.shellSport(arr);

        // 快速排序
//        sortAlgorithm.quickSort(arr,0,arr.length-1);
//        System.out.println("排序后数组【快速排序】：" + Arrays.toString(arr));

//        sortAlgorithm.quickSort();


        // 最大k个数
//        int[] arr1 = new int[10000];
//        for (int i = 0 ; i<10000; i++) {
//            arr1[i] = (int) (Math.random()*10000);
//        }
//        int[] arr1 = {12,23,445,6645,755,77,534,886,86,4,556,78,99,234,56566,4443,453,6666,78788,67};
//        int[] result = sortAlgorithm.MaxNums(arr1,10);
//        System.out.println(Arrays.toString(result));


//        HashMap；
//        TreeMap;
//        ThreadLocal;
//        Hashtable;  线程安全  使用synchronized关键字修饰
//                ConcurrentHashMap;
//        Collections.synchronizedMap();
//        AtomicInteger
//        ReentrantLock;
//        Object;

//        ArrayList arrayList = new ArrayList();
//        Runtime runtime = Runtime.getRuntime();
//        Process process = runtime.exec("");
//        InputStream in = process.getInputStream();
//        Comparator;
//        Long.compare();




    }

    public int maxSlidingWindow(int[] nums, int k) {
        int sum = 0;
        for(int i=0 ; i< nums.length - k ; i++){
            for(int j = 0 ; j<k-1 ; j++){
                int temp = 0;
                temp += nums[i+j];
                sum = (sum > temp) ? sum : temp;
            }

        }
        return sum;
    }











        private Stack<Integer> stack1 = new Stack<Integer>();
        private Stack<Integer> stack2 = new Stack<Integer>();

        public void push(int node){
            while (!stack2.empty()){
                stack1.push(stack2.peek());
                stack2.pop();
            }
            stack1.push(node);
        }

        public int pop(){
            while (!stack1.empty()){
                stack2.push(stack1.peek());
                stack1.pop();
            }
            int temp = stack2.peek();
            stack2.pop();
            return temp ;
        }




















}
